home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 12 code / Globals in Standalone Code / StART ƒ / StARTglue.a < prev   
Encoding:
Text File  |  1992-10-16  |  2.7 KB  |  109 lines  |  [TEXT/MPS ]

  1.         CASE    OFF
  2.  
  3.         INCLUDE    'Traps.a'
  4.         INCLUDE    'QuickEqu.a'
  5.         INCLUDE    'SysEqu.a'
  6.  
  7. FirstByte        MAIN
  8.         IMPORT    Main, _DATAINIT
  9.         ENTRY    gGlobalsOffset
  10.         bra.s    Island
  11.  
  12.         dc.w    0        ; flags
  13.         dc.l    0        ; resType
  14.         dc.w    0        ; ID
  15.         dc.w    0        ; version
  16.         dc.l    0        ; refcon (THINK only)
  17.  
  18. gGlobalsOffset    dc.l    0        ; offset to globals
  19.  
  20. Island
  21.         bra    Main
  22.         lea    _DATAINIT,A0    ; dummy line to reference _DATAINIT
  23.  
  24. ;
  25. ; PROCEDURE UseGlobals(VAR save: SavedA5Rec);    { Balance with DoneWithGlobals. }
  26. ;
  27. UseGlobals    PROC    EXPORT
  28.         IMPORT    GetSAA5
  29.  
  30.         move.l    4(sp),A0        ; get pointer to save record
  31.         move.l    A5,(A0)        ; save A5
  32.         move.l    CurrentA5,4(A0)    ; save low-memory value
  33.         clr.l    -(sp)        ; make room for function result
  34.         bsr.s    GetSAA5        ; get our own A5
  35.         move.l    (sp)+,A5        ; make it real
  36.         move.l    A5,CurrentA5    ; make it really real
  37.         move.l    4(sp),A0        ; get pointer to save record
  38.         move.l    (A0),A0        ; get host’s A5
  39.         move.l    (A0),(A5)        ; copy his porthandle
  40.         move.l    (sp)+,(sp)    ; remove parameters
  41.         rts            ; return to caller
  42.  
  43.  
  44. ;
  45. ; PROCEDURE CopyHostQD(thePort: Ptr; oldA5: Ptr);    { Balance with DoneWithGlobals. }
  46. ;    assumes that A5 has already been set up to our globals
  47. ;
  48. CopyHostQD    PROC    EXPORT
  49.  
  50. returnAddress    EQU    0
  51. oldA5        EQU    returnAddress+4
  52. thePortPtr    EQU    oldA5+4
  53. parameterSize    EQU    thePortPtr-oldA5+4
  54.  
  55.         move.l    oldA5(sp),A0    ; get oldA5
  56.         move.l    (A0),(A5)        ; make (A5) point to thePort
  57.         
  58.         move.l    (A0),A0        ; get host’s thePort pointer
  59.         move.l    thePortPtr(sp),A1    ; get our thePort pointer
  60.         move.l    #grafSize,D0    ; copy whole grafPort
  61.         move.l    D0,D1        ; since the pointers point near the
  62.         subq.l    #4,D1        ; ... end of the QD globals, move them
  63.         sub.l    D1,A0        ; ... down to point to the beginning
  64.         sub.l    D1,A2
  65.         _BlockMove
  66.         
  67.         move.l    (sp)+,A0        ; pop return address
  68.         add    #parameterSize,sp    ; pop parameters
  69.         jmp    (A0)        ; return to caller
  70.  
  71. ;
  72. ; PROCEDURE DoneWithGlobals(restore: SaveA5Rec);
  73. ;
  74. DoneWithGlobals    PROC    EXPORT
  75.  
  76.         move.l    (sp)+,A0        ; pull off return address
  77.         move.l    (sp)+,A1        ; address of record holding info
  78.         move.l    (A1),A5        ; first restore A5
  79.         move.l    4(A1),CurrentA5    ; then restore low-memory value
  80.         jmp    (A0)        ; return to caller
  81.  
  82. ;
  83. ; FUNCTION GetSAA5: LONGINT;
  84. ;
  85. GetSAA5        PROC    EXPORT
  86.         IMPORT    CalculateOffset
  87.  
  88.         move.l    gGlobalsOffset,D0    ; have we done this before?
  89.         bne.s    @1        ; yes, so use cached value
  90.         bsr.s    CalculateOffset    ; nope, so calculate it
  91. @1
  92.         lea    FirstByte,A0    ; get base address
  93.         add.l    A0,D0        ; add offset to top of globals
  94.         move.l    D0,4(sp)        ; set function result
  95.  
  96.         rts            ; return to caller
  97.  
  98. CalculateOffset    PROC
  99.  
  100.         lea    FirstByte,A0    ; get pointer to us
  101.         _RecoverHandle        ; get handle to us
  102.         _GetHandleSize        ; find our size (= offset to end of globals)
  103.         sub.l    #32,D0        ; account for 32 bytes of appParms
  104.         lea    gGlobalsOffset,a0    ; get address to save result
  105.         move.l    D0,(A0)        ; save this offset for later
  106.         rts
  107.  
  108.         END
  109.